package com.automannn.springboot.practice.springApplication;

import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author automannn
 * @time 2021/9/30 13:43
 */
public class SpringApplicationTest {
    public static void main(String[] args) {
        /*xxx: 可以通过指定配置类*/
//        SpringApplication springApplication = new SpringApplication(MyConfiguration.class);
        SpringApplication springApplication = new SpringApplication();

        Set<String> sources = new HashSet<String>();
        /*xxx: 可以是 类名(全限定名)，包名，以及 资源名称 */
//        sources.add(MyConfiguration.class.getName());
        sources.add(NormalClazz.class.getName());

        /*xxx: 也可以通过sources指定*/
        springApplication.setSources(sources);

        /*xxx: 在不设置启动类的情况下，也能启动*/
      ConfigurableApplicationContext applicationContext= springApplication.run(args);
        System.out.println(Arrays.asList(applicationContext.getBeanDefinitionNames()));


    }

    @Component
    public static class MyConfiguration{

        @Bean
        public Object myObj(){
            return new Object();
        }
    }

    public static class NormalClazz{

    }
}
